## Table C1: Covid-19 Effects on Asian Hate Crimes Including all Months Until December 2020

rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(estimatr)
library(texreg)

panel_all <- get(load('./data/panel_month_dummies_all_2020_months.RData'))
panel_all[,covid2:=ifelse(month>'2020-01-01', 1,0)]

## Panel A: Health Threat
out_death_jan_simple <- lm_robust(hc_pc_asians ~ covid2*excess_deaths_jan_d, data=panel_all, se_type='stata',
                                  clusters = panelvar)

if (!file.exists('./output/out_death_jan_2020_all.RData') &
    !file.exists('./output/out_death_jan_con_2020_all.RData') &
    !file.exists('./output/out_death_jan_con_trend_2020_all.RData') &
    !file.exists('./output/out_death_jan_con_trend_all_2020_all.RData')) {
  source('./code/tableC1areg.R')
}

out_death_jan <- get(load('./output/out_death_jan_2020_all.RData'))
out_death_jan_con <- get(load('./output/out_death_jan_con_2020_all.RData'))
out_death_jan_con_trend <- get(load('./output/out_death_jan_con_trend_2020_all.RData'))
out_death_jan_con_trend_all <- get(load('./output/out_death_jan_con_trend_all_2020_all.RData'))

panela <- texreg(list(out_death_jan_simple, out_death_jan, out_death_jan_con, out_death_jan_con_trend, out_death_jan_con_trend_all),
       include.ci = FALSE,
       include.adjrs = FALSE, include.rmse = FALSE,
       stars = c(0.001, 0.01, 0.05), digits = 5,
       custom.coef.map = list('excess_deaths_jan_d' = 'Excess deaths', 'covid2'= 'After Jan, 2020', 
                              'covid2:excess_deaths_jan_d' = 'After Jan, 2020 x Excess deaths',
                              'covid_death' = 'After Jan, 2020 x Excess deaths'),
       symbol = "\\circ",
       caption = "Panel A: Health Threat",
       caption.above = TRUE)

write(panela, file.path('./tableC1_panela.tex'))

## Panel B: Economic Threat
out_econ_simple <- lm_robust(hc_pc_asians ~ covid2*losing_income_d, data=panel_all, se_type='stata', clusters = panelvar)

if (!file.exists('./output/out_econ_2020_all.RData') &
    !file.exists('./output/out_econ_con_2020_all.RData') &
    !file.exists('./output/out_econ_con_trend_2020_all.RData') &
    !file.exists('./output/out_econ_con_trend_all_2020_all.RData')) {
  source('./code/tableC1breg.R')
}

out_econ <- get(load('./output/out_econ_2020_all.RData'))
out_econ_con <- get(load('./output/out_econ_con_2020_all.RData'))
out_econ_con_trend <- get(load('./output/out_econ_con_trend_2020_all.RData'))
out_econ_con_trend_all <- get(load('./output/out_econ_con_trend_all_2020_all.RData'))

panelb <- texreg(list(out_econ_simple, out_econ, out_econ_con, out_econ_con_trend, out_econ_con_trend_all),
       include.ci = FALSE,
       include.adjrs = FALSE, include.rmse = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1), digits = 5,
       custom.coef.map = list('losing_income_d' = 'Expected unemployment', 'covid2'= 'After Jan, 2020', 
                              'covid2:losing_income_d' = 'After Jan, 2020 x Expected unemployment',
                              'covid_econ' = 'After Jan, 2020 x Expected unemployment'),
       symbol = "\\circ",
       caption = "Panel B: Economic Threat",
       caption.above = TRUE)

write(panelb, file.path('./tableC1_panelb.tex'))
